#find_package(TIFF REQUIRED)
#find_package(Qt5 5.4 REQUIRED COMPONENTS Core Widgets Gui Network )
#find_package(CURL REQUIRED)

set(CMAKE_AUTOMOC ON)

function(fnt_plugin name)
	add_library(${name} SHARED "plugins/${name}.cc")
	set_target_properties(${name} PROPERTIES PREFIX "${PACKAGE_NAME}-plugin-")
	target_include_directories(${name} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../shared/public")
	if(MINGW)
		install(TARGETS ${name} RUNTIME DESTINATION "${CMAKE_INSTALL_PLUGINDIR}")
	else(MINGW)
		install(TARGETS ${name} LIBRARY DESTINATION "${CMAKE_INSTALL_PLUGINDIR}")
	endif(MINGW)
	if(${ARGC} GREATER 1)
		target_link_libraries(${name} ${ARGN})
	endif()
endfunction(fnt_plugin)

fnt_plugin(astar)
fnt_plugin(simple)
#fnt_plugin(fnt.find)
fnt_plugin(rayburst Qt5::Gui)
add_subdirectory(plugins/neurolabi)
fnt_plugin(neutube)
target_link_libraries(neutube neurolabi)
target_include_directories(neutube PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/plugins/neurolabi")
target_include_directories(neutube PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/plugins/neurolabi/include")
target_include_directories(neutube PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/plugins/neurolabi/genelib")
if(MINGW)
	target_link_libraries(neutube regex)
endif()

fnt_plugin(retrace fntshared)
target_include_directories(retrace PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../shared")

file(GLOB tracer_SRCS
	"main.cc"
	"tracer.h"
	"cubedata.*"
	"tracer.cc"
	"viewershared.*"
	"loadthreadshared.*"
	"loadthreadpriv.*"
	"viewerpriv.*"
	"annot.tree.*"
	"splash.*"
	"session.cc"
	"session.options.*"
	"sessionpriv.*"
	"common.h"
	"cache.thread.*"
	"load.thread.*"
	"compute.thread.*"
	"xfunc.widget.*"
	"dialogs.*"
	"listmodel.*"
	"labelListmodel.*"
	"options.*"
	"options.dlg.*"
	"options.page.*"
	"plugin.manager.*"
	"QFntLibrary.*"
	"command.*"
	"misc.*"
	"viewer.*"
	"color.widget.*"
	"UpdateWindow.*"
	"DoubleSlider.*"
	"logo.rc"
	)

QT5_ADD_RESOURCES(tracer_QRC resources.qrc)
add_executable(tracer ${tracer_SRCS} ${tracer_QRC})



add_dependencies(tracer astar)
add_dependencies(tracer simple)
add_dependencies(tracer rayburst)
#add_dependencies(tracer neutube)
add_dependencies(tracer fntshared)
add_dependencies(tracer retrace)
if (APPLE)
set(CMAKE_OSX_ARCHITECTURES arm64)

endif (APPLE)

target_link_libraries(tracer debug ${CURL_LIBRARIES_DEBUG} optimized ${CURL_LIBRARIES_RELEASE}  ${TIFF_LIBRARIES} 
Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Network Qt5::Multimedia)
target_link_libraries(tracer)
if(WIN32)
target_link_libraries(tracer Ws2_32 Wldap32  Crypt32 Wldap32 Normaliz )
endif()
target_link_libraries(tracer fntshared)
target_include_directories(tracer SYSTEM PUBLIC ${TIFF_INCLUDE_DIR} ${CURL_INCLUDE_DIR})
target_include_directories(tracer PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../shared/public")
target_include_directories(tracer PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../shared")



if(MINGW)
	target_link_libraries(tracer ws2_32)
endif()
if(APPLE)
	target_link_libraries(tracer ${OpenMP_libomp_LIBRARY} /opt/homebrew/lib/libvpx.dylib)
else()
if(WITH_VP9)
	target_link_libraries(tracer ${VPX_LIBRARIES} )
endif()
endif()
if(WITH_VP9)
	target_link_libraries(tracer  ${WEBM_LIBRARIES})
endif()
if(WITH_HEVC)
	target_link_libraries(tracer ${HEVC_LIBRARIES})
endif()
set_target_properties(tracer PROPERTIES OUTPUT_NAME "${PACKAGE_NAME}-tracer")
install(TARGETS tracer RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")



if(MINGW)
	if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
		add_subdirectory(mingw)
	endif()
elseif(APPLE)
	if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
		add_subdirectory(bundle)
	endif()
else(MINGW)
	if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
		add_subdirectory(linux)
	endif()
endif(MINGW)

add_subdirectory(manual)

